package com.mindskip.xzs.controller.student;

import com.github.pagehelper.PageInfo;
import com.mindskip.xzs.context.WebContext;
import com.mindskip.xzs.domain.dto.student.qusetion.QuestionPageStudentDTO;
import com.mindskip.xzs.domain.entity.ExamPaperQuestionCustomerAnswer;
import com.mindskip.xzs.domain.vo.student.question.QuestionPageStudentVO;
import com.mindskip.xzs.domain.vo.student.question.QuestionSelectStudentVO;
import com.mindskip.xzs.service.ExamPaperQuestionCustomerAnswerService;
import com.mindskip.xzs.utility.RestResponse;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController("StudentQuestionAnswerController")
@RequestMapping(value = "/api/student/question/answer")
public class QuestionAnswerController {

    private final WebContext webContext;
    private final ExamPaperQuestionCustomerAnswerService examPaperQuestionCustomerAnswerService;

    public QuestionAnswerController(WebContext webContext, ExamPaperQuestionCustomerAnswerService examPaperQuestionCustomerAnswerService) {
        this.webContext = webContext;
        this.examPaperQuestionCustomerAnswerService = examPaperQuestionCustomerAnswerService;
    }

    //错题本分页
    @PostMapping("/page")
    public RestResponse<PageInfo<QuestionPageStudentVO>> page(@RequestBody @Valid QuestionPageStudentDTO questionPageStudentDTO) {
        questionPageStudentDTO.setCreateUser(webContext.getCurrentUser().getId());
        PageInfo<QuestionPageStudentVO> page = examPaperQuestionCustomerAnswerService.page(questionPageStudentDTO, webContext.getCurrentUser());
        return RestResponse.ok(page);
    }

    @PostMapping("/select/{id}")
    public RestResponse<QuestionSelectStudentVO> select(@PathVariable Integer id) {
        QuestionSelectStudentVO questionSelectStudentVO = examPaperQuestionCustomerAnswerService.select(id);
        return RestResponse.ok(questionSelectStudentVO);
    }

}
